<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Musor extends Frontend_Controller {

    /**
     * 
     * Index Page for FRONTEND
     * 
     * 
     */
    public function index() {
        $this->data['title'] = "Műsor";
        $this->_load_view('frontend/musor');
    }

    /**
     * 
     * Slugot vár paraméterként, részleteket jelenít meg eventről
     * 
     */
    public function reszletek($slug = NULL) {
        if ($slug == NULL) {
            redirect('musor');
        }

        $this->load->model('event_model');
        $this->data['esemeny_data'] = $this->event_model->get_event_by_slug($slug);

        if ($this->data['esemeny_data'] == NULL) {
            show_404();
        }

        $this->_load_view('frontend/musor_aloldal');
    }

    /**
     * Fullcalendar json output
     */
    public function ajax_get_musor() {
        // json output
        $this->output->set_content_type('application/json');
        // start and end time on linux
        $unix_start = $this->input->post("start");
        $unix_end = $this->input->post("end");

        // ellenőrzés, hogy numerikus-e
        if (!is_numeric($unix_start) || !is_numeric($unix_end)) {
            die("Not a function");
        }

        $start = date('Y-m-d', $unix_start);
        $end = date('Y-m-d', $unix_end);

        $this->load->model('event_model');
        $events = $this->event_model->get_in_range($start, $end);

        //$fullc_events = array();

        foreach ($events as $event) {
            $event->start = $event->esemeny_kezdes;
            $event->end = $event->esemeny_vege;
            $event->title = $event->esemeny_cim;
            // ha van esemény helye akkor kiegészítjük az eseményt a hellyel
            if($event->esemeny_helyszin && $event->esemeny_helyszin != ''){
                $event->title .= " - $event->esemeny_helyszin";
            }
            $event->url = site_url('musor/reszletek/' . $event->esemeny_cim_slug);
            if (!isset($event->backgroundColor) || !$event->backgroundColor || $event->backgroundColor == '') {
                $event->backgroundColor = $event->programsav_szin;
            }else{
                $event->backgroundColor = "#F77825";
            }
            //array_push($fullc_events, $fcevent);
        }

        echo encode_json($events);
    }

}

/* End of file musor.php */
/* Location: ./application/controllers/filmek.php */